package com.webflux.handlers;

import com.webflux.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

@Component
public class ProductHandler {

    @Autowired
    private ProductService service;

    public Mono<ServerResponse> findById(ServerRequest request){

        Integer id = Integer.valueOf(request.pathVariable("productId"));

        return service.findById(id).flatMap(ServerResponse.ok()::bodyValue);

    }

}
